package problem98;

//98.验证二叉搜索树
//https://leetcode.cn/problems/validate-binary-search-tree/

class Solution {
    long preVal = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root == null) return true;

        boolean left = isValidBST(root.left);
        if(!left) return left;

        if(root.val <= preVal) return false;
        preVal = root.val;
       
        boolean right = isValidBST(root.right);
        if(!right) return right;

        return true;
    }
}